import React from 'react';
import {withRouter} from 'react-router-dom';
import {Modal, Button} from 'antd';

import './scss/index.scss';

class RCModal extends React.Component {

    render() {
        let {
            visible = false,
            title = '温馨提示',
            width = 520,
            footerText = {},
            showFooter = true,
            onOk = () => null,
            onCancel = () => null,
            children = null,
            disabled = false
        } = this.props;

        let maskStyle = {
            backgroundColor: 'rgba(0,0,0,0.4)'
        };

        let submitBtn = <Button type="primary" disabled={disabled} key='submit' onClick={onOk}>{footerText.okText || '确认'}</Button>;
        let cancalBtn = <Button key='cancal' onClick={onCancel}>{footerText.cancelText || '取消'}</Button>;
        let footer = [submitBtn, cancalBtn]
        return (
            <Modal title={title}
                visible={visible}
                width={width}
                footer={showFooter ? footer : null}
                onCancel={onCancel}
                centered
                maskClosable={false}
                maskStyle={maskStyle}
                wrapClassName='rcmodal-wrap'
            > { children } </Modal>
        )
    }
}

export default withRouter(RCModal);